#include "RingQueue.hpp"
#include <ctime>
void* Productor(void* args)
{
    sleep(3);
    RingQueue<int>* rq = static_cast<RingQueue<int>*>(args);

    while(true)
    {
        //在这之前还有获取数据的时间....
        int data = rand() % 10 + 1;
        rq->Push(data);
        cout << "procuctor one data, is: " << data << endl;
        sleep(1);
    }
    return nullptr;
}
void* Consumer(void* args)
{
    RingQueue<int>* rq = static_cast<RingQueue<int>*>(args);

    while(true)
    {
        int data = 0;
        rq->Pop(&data);
        cout << "consumer one data, is: " << data << endl;
        //在这之后还有处理数据的时间....
        sleep(1);
    }
    return nullptr;
}
int main()
{
    srand(time(nullptr) ^ getpid());
    RingQueue<int>* rq = new RingQueue<int>();

    pthread_t c,p;

    pthread_create(&c,nullptr,Productor,rq);
    pthread_create(&p,nullptr,Consumer,rq);

    pthread_join(c,nullptr);
    pthread_join(p,nullptr);
    return 0;
}